package org.dc.view;

import android.widget.TimePicker;

/**
 * @user: Vladimir Chernishov
 * @date: 3/10/12
 * @time: 5:16 PM
 */
public class IntervalTimeChangeListener implements TimePicker.OnTimeChangedListener{

    final int interval;

    public IntervalTimeChangeListener(int interval) {
        this.interval = interval;
    }

    public void onTimeChanged(TimePicker timePicker, int hours, int minutes) {
        if(minutes%interval == 0){
            //do nothing
        }else if((minutes%interval) == 1){
            int currentMinute = (minutes / interval + 1) * interval;
            timePicker.setCurrentMinute(currentMinute >= 60 ? 0 : currentMinute);
        } else {
            timePicker.setCurrentMinute((minutes / interval) * interval);
        }
    }

}
